<template>
  <header
    class="common-header"
    :style="{
      height: typeof height === 'string' ? height : height + 'px',
      ...(customStyle ?? {}),
    }"
  >
    <div class="c-h__slot-title fix-width">
      <slot name="title">
        <h2 class="common-header__title">{{ title }}</h2>
      </slot>
    </div>
    <div v-if="showCenter" class="c-h__slot-center">
      <slot name="center">
        <a-input placeholder="全局搜索">
          <template #suffix>
            <SearchOutlined />
          </template>
        </a-input>
      </slot>
    </div>
    <div class="c-h__slot-extra fix-width">
      <slot name="extra">
        <UserInfo :user-info="userStore.userInfo"></UserInfo>
      </slot>
    </div>
  </header>
</template>

<script setup lang="ts">
import { useUserStore } from '@/stores/user';
import { SearchOutlined } from '@ant-design/icons-vue';
import UserInfo from './components/UserInfo.vue';
interface IProp {
  title?: string;
  height?: number | string;
  background?: string;
  customStyle?: Record<string, any>;
  showCenter?: boolean;
}
const props = defineProps<IProp>();
const userStore = useUserStore();
</script>
<style lang="less" scoped>
.common-header {
  width: 100%;
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #0000000e;
  background-color: v-bind('props.background');

  &__title {
    color: #000000e0;
    font-size: 20px;
    font-weight: 600;
    line-height: 28px;
    margin: 0 !important;
  }

  .fix-width {
    width: 33%;
  }

  .c-h__slot-extra {
    display: flex;
    justify-content: flex-end;
  }
}
</style>
